import { Module } from '@nestjs/common';
import { DictionaryService } from './dictionary.service';
import { DictionaryController } from './dictionary.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { DictionaryWords } from '@/entity/dictionary-words.entity';
import { Dictionary } from '@/entity/dictionary.entity';
import { MulterModule } from '@nestjs/platform-express';
import dayjs = require('dayjs');
import { diskStorage } from 'multer';
import * as nuid from 'nuid';
import { DictionaryStudyRecord } from '@/entity/dictionary-study-record.entity';
import { DictionaryStudyRecordError } from '@/entity/dictionary-study-record-error.entity';
import { DictionaryCollection } from '@/entity/dictionary-collection.entity';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      Dictionary,
      DictionaryWords,
      DictionaryStudyRecord,
      DictionaryStudyRecordError,
      DictionaryCollection,
    ]),
    MulterModule.register({
      storage: diskStorage({
        //自定义路径
        destination: `./fileUpload/${dayjs().format('YYYY-MM-DD')}`,
        filename: (req, file, cb) => {
          // 自定义文件名
          const filename = `${nuid.next()}.${file.mimetype.split('/')[1]}`;
          return cb(null, filename);
        },
      }),
    }),
  ],
  providers: [DictionaryService],
  controllers: [DictionaryController],
})
export class DictionaryModule {}
